<template>
  <div>
    <textarea cols="30" rows="10" v-model="content"></textarea>
    <button @click="addComment">点击评论</button>
  </div>
</template>

<script>
import * as api from "@/api/comment";
import { mapActions } from "vuex";
export default {
  data() {
    return {
      content: "",
      name: "ikun",
    };
  },
  methods: {
    ...mapActions("comment", ["FETCH_COMMENT"]),
    async addComment() {
      let res = await api.addComment(this.content, this.name);
      console.log(res);
      if (res.data.state) {
        //添加成功，重新获取列表，更新数据
        this.FETCH_COMMENT();
      }
    },
  },
};
</script>
